﻿package framework.core;

import java.io.*;

public class Logger
{
	public static void throwException(Object srcObject,String msg) throws Exception 
	{
		Exception e = new Exception(msg);
		logException(srcObject,e);
		throw e;
	}
	public static void throwException(Object srcObject,Exception e) throws Exception 
	{
		logException(srcObject,e);
		throw e;
	}
	public static void logException(Object srcObject,Throwable e)
	{
		String s = "["+new DateUtil().toString()+"][exception]" + "["+srcObject.toString()+ "]:" + e.getMessage() ;
		logMessage(s);
	}
	public static void log(Object srcObject,String msg)
	{
		String s = "["+new DateUtil().toString()+"][message]" + "["+srcObject.toString()+ "]:" + msg ;
		logMessage(s);
	}
	public static String  getExceptionTrace(Throwable e)
	{
		if(null==e) return "NULL Exception";
		ByteArrayOutputStream stream = new ByteArrayOutputStream();
		PrintWriter w = new PrintWriter(stream,true);
		e.printStackTrace(w);
		return stream.toString();
	}
	private static void logMessage(String msg)
	{
		if(Config.isDebugPrint()) 
		{
			System.out.println(msg);
		} 
		if(Config.isDebugLog())
		{
			//TODO add log business  
		}
	}
}
